from django.urls import path
from books.views import index, readbook, login, login_json, header, detail
from books.views import jsonresponse, to_index
from books import views

from django.urls import converters

urlpatterns = [
    path('index/', index),

    path('<cat_id>/<book_id>/', readbook),

    path('login/', login),
    path('login_json/', login_json),
    path('header/', header),
    path('detail/', detail),
    path('jsonresponse/', jsonresponse),
    path('to_index/', to_index),
    path('register/<mobile:phone>/',views.tieba_register),
path('register/<mobile:phone>/',views.tieba_register),


    path('login/',views.tieba_login),
    path('get_cookie/',views.get_cookie),

    # 设置session
    path('set_session/',views.set_session),
    path('get_session/',views.get_session),

    ###################################
    path('jd_register/',views.jd_register),

    # 类视图的路由
    # path 的参数1  路由
    # path 的参数2  视图函数名
    path('meiduo_register/',views.RegisterView.as_view()),


    # 个人中心路由
    path('center/',views.CenterView.as_view()),
]


class MobileConverter:
    # 正则的属性 必须这么写
    regex='1[3-9]\d{9}'

    # 验证之后的数据,要给视图函数
    def to_python(self,value):
        # value 就是要验证的数据
        return value

converters.register_converter(MobileConverter,'mobile')
